<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var list = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3];

    // 把数组的元素作为对象的键名  (对象的键名是唯一的  )
    // 缺点: 对象的键名只能值字符串类型

    /* var obj = {}
    for(var i=0;i<list.length;i++){
        var item = list[i]; 
        if(obj.hasOwnProperty(item)){
            obj[item]++;         
        }else{
            obj[item] = 1;  //  obj["1"]
        }
    }
    console.log(obj);

    var unique = [];
    for(var key in obj){
        unique.push(key);
    }
    console.log(unique); */


    var m = new Map();
    for(var i=0;i<list.length;i++){
        var item = list[i]; 
        if(m.has(item)){
            m.set(item,m.get(item)+1)         
        }else{
            m.set(item,1);  //  obj["1"]
        }
    }
    console.log(m);

    var unique = [];
    m.forEach((val,key)=>{
        unique.push(key);
    })
    console.log(unique);

</script>

</html>